<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>发送短信</title>
    <style type="text/css">
    </style>
    <jsp:include page="../../import.jsp" flush="true"/>
    <script type="text/javascript">
        $(function () {
            $("#sendsms_form").ligerForm({
                validate: true
            });
            $("#dateform").ligerForm();
            $("#clearBtn").click(function(event) {
                $("#phoneList").val("");
                $("#content").val("");
            });
        });
        //批量导入
        function addBatch(){
            //获取上传文件地址
            var files=getUploadResultParams();
            if(files&&files.length>0){
                var filePath=files[0].filePath;
                var fileExtension = filePath.substring(filePath.lastIndexOf('.') + 1);
                if(fileExtension!='xls'&&fileExtension!='XLS'){
                    $.ligerDialog.SQalert({content: "请上传.xls后缀的文件", SQ_type: "warn"});
                    return;
                }
                    var wait_dialog;
                    $.ajax({
                        type: 'post',
                        dataType:'json',
                        data:"filePath="+filePath,
                        url: '<%=path%>/syssms/sysSmsLog/sendPhone.do',
                        beforeSend: function(){
                            wait_dialog=$.ligerDialog.SQalert({content: '正在解析excel...' ,SQ_type: "waitting" });
                        },
                        success:function(msg){
                            wait_dialog.close();
                            if(msg.success == 1){
                                $("#phoneList").val(msg.data);
                            }else{
                                $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
                            }
                        }
                    });
            }else{
                $.ligerDialog.SQalert({content: "请先上传文件", SQ_type: "warn"});
            }
        }
        //下载模板
        function downTemp(){
            window.location.href="<%=path%>/resource/template/syssms/sendsmsTemp.xls";
        }
        //立即发送
        function startSendSMS(){
            var phonelist = $("#phoneList").val();
            if(phonelist==""){
                $.ligerDialog.SQalert({content: "手机号不能为空!",SQ_type: "warning"});
                return false;
            }
            var content = $("#content").val();
            if(content==""){
                $.ligerDialog.SQalert({content: "短信内容不能为空!",SQ_type: "warning"});
                return false;
            }
            $.ligerDialog.confirm("是否立即发送?", function (flag) {
                if(flag == false)return;
                var wait_dialog;
                $.ajax({
                    type: 'post',
                    dataType:'json',
                    data:'phonelist='+phonelist+'&content='+content,
                    url: '<%=path%>/syssms/sysSmsLog/startSendSMS.do',
                    beforeSend: function(){
                        wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
                    },
                    success:function(msg){
                        wait_dialog.close();
                        if(msg.success == 1){
                            $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
                            $("#phoneList").val("");
                            $("#content").val("");
                            if (parent.pageInTab) {
                                parent.pageInTab.selectTabItem('SendRecord');
                                parent.pageInTab.reload('SendSms');
                                parent.pageInTab.reload('SendRecord');
                            }
                        }else{
                            $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
                        }
                    }
                });
            });
        }
        //预约发送
        function waitSendSms(){
            var phonelist = $("#phoneList").val();
            if(phonelist==""){
                $.ligerDialog.SQalert({content: "手机号不能为空!",SQ_type: "warning"});
                return false;
            }
            var content = $("#content").val();
            if(content==""){
                $.ligerDialog.SQalert({content: "短信内容不能为空!",SQ_type: "warning"});
                return false;
            }
            $.ligerDialog.confirm("是否预约发送?", function (flag) {
                if(flag == false)return;
            var _dialog = $.ligerDialog.open({
                target: $("#modifysendDatediv"),
                title: '选择时间',
                width: 500,
                height: 150,
                isResize: true,
                modal: true,
                buttons: [{ text: '确定', onclick: function (i, d) {
                        var modifysendday = $("#modifysendday").val();
                        if (modifysendday == '') {
                            top.$.ligerDialog.SQalert({content: "预约日期不能为空",SQ_type: "warning"});
                            return false; //验证不通过，不执行以下代码
                        }
                        var modifysendhour = $("#modifysendhour").val();
                        $("#modifysendday").val("");
                        $("#modifysendhour").val("09:00");
                        //$("input:radio[name='hourdate']:checked").removeAttr("checked");
                        //$("input:radio[name='hourdate']").eq(0).attr("checked",true);
                        $("input:radio[name='hourdate']").eq(0).siblings('a').click();
                        _dialog.hide();
                        var wait_dialog;
                        $.ajax({
                            type: 'post',
                            dataType:'json',
                            data:'sendday='+modifysendday+'&sendhour='+modifysendhour+'&phonelist='+phonelist+'&content='+content,
                            url: '<%=path%>/syssms/sysSmsLog/waitSendSms.do',
                            beforeSend: function(){
                                wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
                            },
                            success:function(msg){
                                wait_dialog.close();
                                if(msg.success == 1){
                                    $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
                                    $("#phoneList").val("");
                                    $("#content").val("");
                                    if (parent.pageInTab) {
                                        parent.pageInTab.selectTabItem('ReserRecord');
                                        parent.pageInTab.reload('SendSms');
                                        parent.pageInTab.reload('ReserRecord');
                                    }
                                }else{
                                    $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
                                }
                            }
                        });

                }
                }, { text: '关闭', onclick: function (i, d) {
                    $("#modifysendday").val("");
                    $("#modifysendhour").val("09:00");
                    //$("input:radio[name='hourdate']:checked").removeAttr("checked");
                    //$("input:radio[name='hourdate']").eq(0).attr("checked",true);
                    $("input:radio[name='hourdate']").eq(0).siblings('a').click();
                    _dialog.hide();
                }
                }]
            });
            });
        }
        //选择时间
        function selecthour(_hour){
            $("#modifysendhour").val(_hour);
        }
    </script>
</head>

<body class="iframeBody">
<form id="sendsms_form">
    <div class="fieldset1 tabel_col tabel_col_1 clearFix">
        <div class="fieldBox col_100">
            <div class="label">批量导入</div>
            <div class="field">
                <jsp:include page="../../system/sysUlFilesRec/sysSysUlFilesRecUpload.jsp" flush="true" >
                    <jsp:param name="fileNum" value="1"/>
                    <jsp:param name="filePath" value="syssms/syssmslog"/>
                </jsp:include>
                <span id="addBatchBtn" class="sq-button sq-button-hasicon" onclick="addBatch();"><i class="sqBtnIco_33"></i>批量导入</span>
                <span id="downTempBtn" class="sq-button sq-button-hasicon" onclick="downTemp();"><i class="sqBtnIco_8"></i>下载模板</span>
            </div>
        </div>
        <div class="fieldBox col_100">
            <div class="label">发送列表</div>
            <div class="field">
                <textarea name="phoneList" id="phoneList" class="ui-textarea l-textarea" rows="4" cols="120" validate="{required:false,maxlength:2000}"></textarea>
            </div>
        </div>
        <div class="fieldBox col_100">
            <div class="label">短信内容</div>
            <div class="field">
                <textarea name="content" id="content" class="ui-textarea l-textarea" rows="4" cols="120" validate="{required:false,maxlength:2000}"></textarea>
            </div>
        </div>
        <div class="fieldBox">
            <div class="label"></div>
            <div class="field">
                <div style="margin-left:140px">
                <span style="color:red;">
                    注：(1)发送给多个手机号每个手机号要以英文分号(;)隔开，例如:13588888888;13699999999;13711111111
                    <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(2)点击“预约发送”弹出时间选择框，选择日期，选定时间后点击保存后将自动生成一条待发送的短信。在待发送中可查询。
                    <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(3)短信内容在63个字符以内每人每条扣短信条数为1，以此类推以63为基数费为翻倍。
                </span>
                </div>
            </div>
        </div>
    </div>
    <div class="btnsBox">
        <span id="submitBtn" class="sq-button" onclick="startSendSMS()">立即发送</span>
        <span id="waitSend" class="sq-button" onclick="waitSendSms()">预约发送</span>
        <span id="clearBtn" class="sq-button">清空</span>
    </div>
</form>
<div id="modifysendDatediv" style="display:none">
    <form id="dateform">
        <div class="fieldset1 clearFix">
            <div class="fieldBox col_33">
                <div class="label">请选择日期:</div>
                <div class="field">
                    <input name="modifysendday" id="modifysendday" type="text" class="ui-datepicker" value="">
                </div>
            </div>
            <div class="clearFix"></div>
            <div class="fieldBox col_33">
                <div class="label">请选择时间:</div>
                <div class="field">
                    <input type="hidden" id="modifysendhour" value="09:00" />
                    <input type="radio" name="hourdate" class="hourdate" onclick="selecthour('09:00')" checked  >9点</input>
                    <input type="radio" name="hourdate" class="hourdate" onclick="selecthour('10:00')" >10点</input>
                    <input type="radio" name="hourdate" class="hourdate" onclick="selecthour('11:00')" >11点</input>
                    <input type="radio" name="hourdate" class="hourdate" onclick="selecthour('14:00')" >14点</input>
                    <input type="radio" name="hourdate" class="hourdate" onclick="selecthour('15:00')" >15点</input>
                    <input type="radio" name="hourdate" class="hourdate" onclick="selecthour('16:00')" >16点</input>
                    <input type="radio" name="hourdate" class="hourdate" onclick="selecthour('17:00')" >17点</input>
                </div>
            </div>
        </div>
    </form>
</div>
</body>
</html>
